package com.pan.basic;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

public class DirectMomoryOOM {

    private  static final int _1MB = 1024*1024;

    public static void main(String[] args) throws IllegalAccessException {
        //
        Field unsafeField = Unsafe.class.getDeclaredFields()[0];
        unsafeField.setAccessible(true);
        Unsafe unsafe = (Unsafe)unsafeField.get(null);
        int index=0;
        while (true){
            System.out.println(index++);
            unsafe.allocateMemory(_1MB);
        }

    }
}
